﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace StockSBDetails.webutil
{
    public class HttpGet
    {
        public static string requestBig5(string url)
        {
            HttpWebResponse webResponse = null;
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.Method = "POST";
            string responseStr = null;
            webRequest.Timeout = 50000;
            webRequest.ContentType = "text/html; charset=big5";
            try
            {
                webResponse = (HttpWebResponse)webRequest.GetResponse();
            }
            catch (WebException e)
            {
                responseStr = "Error happen! please try later";
            }
            catch (Exception e)
            {
                //发生异常时把错误信息当作错误信息返回
                responseStr = "Error msg:" + e.Message;

            }
            finally
            {
                if (webResponse != null)
                {
                    //获得网络响应流
                    using (StreamReader responseReader = new StreamReader(webResponse.GetResponseStream(), Encoding.GetEncoding("BIG5")))
                    {
                        responseStr = responseReader.ReadToEnd();//获得返回流中的内容
                    }
                    webResponse.Close();//关闭web响应流
                }
            }
            return responseStr;
        }
    }
}
